package com.example.facemanager.util;

import com.example.facemanager.vo.ReturnMsg;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * @Author huchenying
 * @Date 2022/8/5 11:09
 * @Description
 */
public class BaiduAlReturnMsgTrans {

    public static ReturnMsg trans(String result){
        System.out.println(result);
        JSONObject json = new JSONObject(result);
        int code = json.getInt("error_code");
        String msg = json.getString("error_msg");
        if(code == 0){
            JSONObject data = null;
            try {
                data = json.getJSONObject("result");
            } catch (JSONException e) {
//                throw new RuntimeException(e);
                return ReturnMsg.success();
            }
            return ReturnMsg.success(data);
        }else {
            return ReturnMsg.fail(msg);
        }
    }
}
